package com.ksd.system.service.impl;

import java.util.List;

import com.ksd.common.constant.UserConstants;
import com.ksd.common.core.domain.entity.SysUser;
import com.ksd.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ksd.system.mapper.SysChannelTemplateMapper;
import com.ksd.system.domain.SysChannelTemplate;
import com.ksd.system.service.ISysChannelTemplateService;

/**
 * 频道模板Service业务层处理
 * 
 * @author y.wu
 * @date 2025-03-23
 */
@Service
public class SysChannelTemplateServiceImpl implements ISysChannelTemplateService 
{
    @Autowired
    private SysChannelTemplateMapper sysChannelTemplateMapper;

    /**
     * 查询频道模板
     * 
     * @param id 频道模板主键
     * @return 频道模板
     */
    @Override
    public SysChannelTemplate selectSysChannelTemplateById(Long id)
    {
        return sysChannelTemplateMapper.selectSysChannelTemplateById(id);
    }

    @Override
    public SysChannelTemplate selectSysChannelTemplateByName(String name) {
        return sysChannelTemplateMapper.selectSysChannelTemplateByName(name);
    }



    /**
     * 查询频道模板列表
     * 
     * @param sysChannelTemplate 频道模板
     * @return 频道模板
     */
    @Override
    public List<SysChannelTemplate> selectSysChannelTemplateList(SysChannelTemplate sysChannelTemplate)
    {
        return sysChannelTemplateMapper.selectSysChannelTemplateList(sysChannelTemplate);
    }

    @Override
    public List<SysChannelTemplate> selectSysChannelTemplateListByChannelId(SysChannelTemplate sysChannelTemplate) {
        return sysChannelTemplateMapper.selectSysChannelTemplateListByChannelId(sysChannelTemplate);
    }

    /**
     * 新增频道模板
     * 
     * @param sysChannelTemplate 频道模板
     * @return 结果
     */
    @Override
    public int insertSysChannelTemplate(SysChannelTemplate sysChannelTemplate)
    {
        return sysChannelTemplateMapper.insertSysChannelTemplate(sysChannelTemplate);
    }

    /**
     * 修改频道模板
     * 
     * @param sysChannelTemplate 频道模板
     * @return 结果
     */
    @Override
    public int updateSysChannelTemplate(SysChannelTemplate sysChannelTemplate)
    {
        return sysChannelTemplateMapper.updateSysChannelTemplate(sysChannelTemplate);
    }

    /**
     * 批量删除频道模板
     * 
     * @param ids 需要删除的频道模板主键
     * @return 结果
     */
    @Override
    public int deleteSysChannelTemplateByIds(Long[] ids)
    {
        return sysChannelTemplateMapper.deleteSysChannelTemplateByIds(ids);
    }

    /**
     * 删除频道模板信息
     * 
     * @param id 频道模板主键
     * @return 结果
     */
    @Override
    public int deleteSysChannelTemplateById(Long id)
    {
        return sysChannelTemplateMapper.deleteSysChannelTemplateById(id);
    }

    @Override
    public boolean checkSourceUrlUnique(SysChannelTemplate sysChannelTemplate) {
        Long userId = StringUtils.isNull(sysChannelTemplate.getId()) ? -1L : sysChannelTemplate.getId();
        SysChannelTemplate info = sysChannelTemplateMapper.checkSourceUrlUnique(sysChannelTemplate.getSourceUrl());
        if (StringUtils.isNotNull(info) && info.getId().longValue() != userId.longValue())
        {
            return UserConstants.NOT_UNIQUE;
        }
        return UserConstants.UNIQUE;
    }

    @Override
    public boolean checkNameUnique(SysChannelTemplate sysChannelTemplate) {
        Long userId = StringUtils.isNull(sysChannelTemplate.getId()) ? -1L : sysChannelTemplate.getId();
        SysChannelTemplate info = sysChannelTemplateMapper.checkNameUnique(sysChannelTemplate.getName());
        if (StringUtils.isNotNull(info) && info.getId().longValue() != userId.longValue())
        {
            return UserConstants.NOT_UNIQUE;
        }
        return UserConstants.UNIQUE;
    }
}
